#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

int dp[100];

int main() {
    int m, n;
    while (scanf("%d", &m) != EOF) {
        scanf("%d", &n);
        int a[n];
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        for (int i = 0; i < 100; i++) {
            dp[i] = n + 1;
        }

        dp[0] = 0;  dp[a[0]] = 1;

        for (int i = 1; i < n; i++) {
            for (int j = m; j >= a[i]; j--) {
                dp[j] = fmin(dp[j], dp[j - a[i]] + 1);
            }
        }

        if (dp[m] <= n) {
            printf("%d\n", dp[m]);
        }
        else {
            puts("0");
        }
    }
    return 0;

}
